import { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";
import { message } from "antd";
const useAuth=()=>{
    const nav=useNavigate()
    let [isAuth,setIsAuth]=useState(()=>{
        const token=localStorage.getItem('token')
        return !!token
    })
    useEffect(()=>{
        let token=localStorage.getItem('token')
        if(!token){
            setIsAuth(false)
            message.error('请先登录')
            nav('/login')
        }
    },[nav])
return isAuth
}
export default useAuth